package com.sensePlusVR.activity.mine;

import org.xutils.x;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sensePlusVR.base.BaseActivity;
import com.sensePlusVR.main.R;
import com.sensePlusVR.utils.AppManager;
import com.sensePlusVR.utils.Constant;
import com.sensePlusVR.utils.Constant.Sex;
import com.sensePlusVR.utils.MyLog;
import com.sensePlusVR.utils.MyPageJump;
import com.sensePlusVR.utils.MySharedPreferences;
/**
 * 
 * @author: Loren
 * @create: 2016-8-10下午2:47:54
 * @desc: My -->用户设置
 *
 */
@SuppressWarnings("unused")
@ContentView(R.layout.activity_setting_user)
public class UserSettingActivity extends BaseActivity implements OnClickListener{
	private static final String TAG = UserSettingActivity.class.getSimpleName();
	
	@ViewInject(R.id.title_bar_left_ib)
	private ImageButton title_bar_left_ib;
	
	@ViewInject(R.id.title_bar_title_tv)
	private TextView title_bar_title_tv;
	
	@ViewInject(R.id.setting_user_nickname)
	private TextView setting_user_nickname;
	
	@ViewInject(R.id.setting_user_gender)
	private TextView setting_user_gender;
	
	@ViewInject(R.id.setting_user_nickname_linear)
	private RelativeLayout setting_user_nickname_linear;
	
	@ViewInject(R.id.setting_user_gender_linear)
	private RelativeLayout setting_user_gender_linear;
	
	
	@Override
	public void setMyContentView() {
		x.view().inject(this);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		//TODO 获取用户信息
		String userName = MySharedPreferences.getString2(UserSettingActivity.this, MySharedPreferences.NAME_NOT_CLEAR,Constant.LOGIN_SUCCESS_SHOWNAME);
		String nickName = "";
		int lastIndex = userName.indexOf("@");
		if(lastIndex == -1)
			nickName = userName;
		else
			nickName = userName.substring(0, lastIndex);
		setting_user_nickname.setText(nickName);
		
		String userSex = MySharedPreferences.getString2(UserSettingActivity.this,MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_SEX);
		if(userSex == null || userSex==""){
			userSex = Sex.MALE;
		}
		setting_user_gender.setText(userSex);
		
		MyLog.d(TAG, "nickName : " + nickName + " userSex : " + userSex);
		
	}
	
	@Override
	public void beforeView() {
		super.beforeView();
		AppManager.getInstance().addActivity(this);
		title_bar_title_tv.setText(R.string.personal_information);
	}
	
	@Override
	public void initView() {
		super.initView();
		title_bar_left_ib.setOnClickListener(this);
		setting_user_nickname_linear.setOnClickListener(this);
		setting_user_gender_linear.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_bar_left_ib:
			AppManager.getInstance().finishActivity(this);
			break;
		case R.id.setting_user_nickname_linear:
			MyPageJump.pageJump(UserSettingActivity.this, ModifyUNActivity.class);
			break;
		case R.id.setting_user_gender_linear:
			MyPageJump.pageJump(UserSettingActivity.this, ModifySexActivity.class);
			break;
		}
	}

}
